var _mysql = require('mysql');

var HOST = 'localhost';
var PORT = 3306;
var MYSQL_USER = 'uxperf';
var MYSQL_PASS = 'uxperf';
var DATABASE = 'uxperf';
var TABLE = 'datapkgs'; 		// oryginalna baza zawierajaca JSON
var TABLEAN = 'uxperfAN'; 		// baza do analizy pogrupowanych danych
var TABLE_DATA_AN = 'dataAN'; 

var mysql = _mysql.createClient({
    host: HOST,
    port: PORT,
    user: MYSQL_USER,
    password: MYSQL_PASS,
});

mysql.query('use ' + DATABASE);

// pobieranie danych z bazy
console.log('pobieranie danych');
console.log('------------------------');


function getData(cb) {

  var res = []; 

  mysql.query(
    'SELECT id, day FROM ' +TABLEAN,
    function selectCb(error, results, fields) {
      if (error) {
          console.log('GetData Error: ' + error.message);
          mysql.end();
          return;
      }
	  
      for (var i in results) {
			var row = results[i];								// pojedynczy rekord
			//console.log('ID= '+row.id+' DAY= '+row.day);
	  } 
	  //console.log(results);	  
	  res = results;
	  cb(res);
	  console.log('end');	
  }); 
};

getData( function(res) {
    console.log(res);    
});

